from myelin.Ns import MYELINS
from Reset import Form
 
        
class Form(Form):
    
    def createInstance(self, context, node):
        #defaults = context.defaults        
        eventData = context.event.data
       
        params = eventData.params
        errors = eventData.errors
        
        e_get = errors.get
        p_get = params.get
        
        nxa = node.xml_append
        nxc = node.xml_create_element
        
        curNode = self.createMethodOptions(
            context,
            nxa(
                nxc(
                    u'a:method', MYELINS
                )            
            ),
            (context.nodeType.actions.get(self.defaultSubmitAction) or {}).keys()
        )
        e = e_get('method')
        if e:
            curNode.error = e
        
        self.createDefaultGraphsOptions(
            context,
            nxa(
                nxc(
                    u'a:default-graphs', MYELINS
                )
            )
        )
        
        curNode = nxa(
            nxc(
                u'a:nsmaps', MYELINS,
                content = p_get('nsmaps') or None
            )
        )
        e = e_get('nsmaps')
        if e:
            curNode.error = e
        
        curNode = nxa(
            nxc(
                u'a:query', MYELINS,
                content = p_get('query') or None
            )
        )
        e = e_get('query')
        if e:
            curNode.error = e
        
        return node